//
//  BaseViewController.swift
//  appstore
//
//  Created by 王雷 on 2019/11/2.
//  Copyright © 2019 Roy. All rights reserved.
//

import UIKit

class BaseViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    
    // 改变 navigationBar backgroundColor
    func changeNavigationBarBackground() -> Void {
        let navBarAppearance = UINavigationBarAppearance()
        navBarAppearance.configureWithOpaqueBackground()
        navBarAppearance.backgroundColor = .white
        navBarAppearance.shadowColor = nil
        navigationController?.navigationBar.standardAppearance = navBarAppearance
        navigationController?.navigationBar.scrollEdgeAppearance = navBarAppearance
    }
    
    // 设置导航栏右侧按钮
    func setNavigationBarUserItem(target:Any,action:Selector) -> Void {
        let rightItem = UIButton(type: .custom)
        rightItem.frame = CGRect(x: 0.0, y: 0.0, width: 40.0, height: 40.0)
        rightItem.setImage(UIImage(named: "demo_icon"), for: .normal)
        rightItem.addTarget(target, action: action, for: .touchUpInside)
        let leftView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 40.0, height: 40.0))
        leftView.layer.cornerRadius = 20.0
        leftView.layer.masksToBounds = true
        leftView.addSubview(rightItem)
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: leftView)
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
